package com.jzr.board.ui.fragment.main

import android.annotation.SuppressLint
import android.graphics.Canvas
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.utils.LogUtils
import com.blankj.utilcode.utils.TimeUtils
import com.blankj.utilcode.utils.ToastUtils
import com.chad.library.adapter.base.callback.ItemDragAndSwipeCallback
import com.chad.library.adapter.base.listener.OnItemSwipeListener
import com.jzr.board.R
import com.jzr.board.base.BaseApplication
import com.jzr.board.base.BaseEvenBus
import com.jzr.board.base.BaseFragment
import com.jzr.board.bean.*
import com.jzr.board.bean.body.UpdateCareLabelBody
import com.jzr.board.bean.body.UpdateNursingBody
import com.jzr.board.presenter.contract.PatientListFragmentContract
import com.jzr.board.presenter.impl.PatientListFragmentImpl
import com.jzr.board.ui.adapter.*
import com.jzr.board.utils.CommonUtil
import com.jzr.board.utils.PreferUtil
import com.jzr.board.view.ColorPickerView
import com.jzr.board.view.CustomDialog
import com.jzr.board.view.SpacesItemDecoration
import kotlinx.android.synthetic.main.fragment_beadinfo.*
import org.greenrobot.eventbus.EventBus
import java.util.*
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import kotlin.Comparator
import kotlin.collections.ArrayList
import kotlin.collections.HashMap


open class PatientListFragment : BaseFragment(), PatientListFragmentContract.View,
    View.OnClickListener,
    PatientListApadter.onListItemClick, CheckAdapter.onListItemClick {

    private val mPresenter = PatientListFragmentImpl()

    companion object {
        fun newInstance(): PatientListFragment? {
            return PatientListFragment()
        }

        var patientListAll = mutableListOf<PatientListBean.DataBean>()

    }

    private val patientListDanger = mutableListOf<PatientListBean.DataBean>()
    private val patientListPeril = mutableListOf<PatientListBean.DataBean>()
    private val patientListSuper = mutableListOf<PatientListBean.DataBean>()
    private val patientListOne = mutableListOf<PatientListBean.DataBean>()
    private val patientListTwo = mutableListOf<PatientListBean.DataBean>()
    private val patientListThree = mutableListOf<PatientListBean.DataBean>()
    private val patientListEmpty = mutableListOf<PatientListBean.DataBean>()
    private val patientListPresent = mutableListOf<PatientListBean.DataBean>()
    private val patientListHospitalized = mutableListOf<PatientListBean.DataBean>()
    private val patientListOperation = mutableListOf<PatientListBean.DataBean>()


    private var adapter: PatientListApadter? = null
    private var patientListData = mutableListOf<PatientListBean.DataBean>()
    private var patientItem: PatientListBean.DataBean? = null

    private var scheduledFuture: ScheduledFuture<*>? = null
    private var isAuto = false
    private var manager: GridLayoutManager? = null

    private var patientDialog: CustomDialog? = null
    private var checkDialog: CustomDialog? = null
    private var careLabelDialog: CustomDialog? = null
    private var categoryListDialog: CustomDialog? = null
    private var careLabelListDialog: CustomDialog? = null
    private var checkColorDiaolog: CustomDialog? = null
    private var testDiaolog: CustomDialog? = null
    private var inspectDiaolog: CustomDialog? = null
    private var feeDiaolog: CustomDialog? = null
    private var drugDiaolog: CustomDialog? = null
    private var temDiaolog: CustomDialog? = null
    private var bloodDiaolog: CustomDialog? = null

    private var typeCheck: Int? = null
    private var typeCheckColor: Int? = null

    private var tvNName: TextView? = null
    private var tvPName: TextView? = null
    private var tvColor: TextView? = null
    private var tvFontColor: TextView? = null
    private var tvEditCarelabel: TextView? = null

    private var patientCareLabelAdapter: PatientCareLabelAdapter? = null
    private var rvPatientCareLabel: RecyclerView? = null

    private var rvAddCarelabel: RecyclerView? = null
    private var addCareLabelAdapter: PatientCareLabelAdapter? = null

    private var labelName: String? = null
    private var bgColor: String? = null
    private var fontColor: String? = null
    private var labelId: Int? = null

    private val labelIds = mutableListOf<Int>()

    private var nurseCode: String? = null // 责任护士编码
    private var nurseCode2: String? = null // 值班护士编码

    override fun getLayoutResId(): Int {
        return R.layout.fragment_beadinfo
    }

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        adapter = PatientListApadter(patientListData)
        val params = ViewGroup.LayoutParams(
            PreferUtil.getInstance().widthValue,
            PreferUtil.getInstance().hightValue
        )
        adapter?.setLayoutParams(params)
        adapter?.setTextSize(
            PreferUtil.getInstance().typefaceNameValue,
            PreferUtil.getInstance().typefaceValue,
            PreferUtil.getInstance().infusionTypefaceValue
        )

        adapter?.onListItemClick(this)
        rvTitle.addItemDecoration(SpacesItemDecoration(8))
        manager = GridLayoutManager(
            getSupportActivity(),
            PreferUtil.getInstance().itemValue
        )

        rvTitle.layoutManager = manager
        rvTitle.addOnScrollListener(scrollListener)

        scheduledFuture =
            BaseApplication.MAIN_EXECUTOR.scheduleWithFixedDelay({
                getPatientList()
            }, 0, 1, TimeUnit.HOURS)

        rvTitle.adapter = adapter
        tvItemValue.text = PreferUtil.getInstance().itemValue.toString()
        tvTypefaceValue.text = PreferUtil.getInstance().typefaceValue.toString()
        tvWidthValue.text = PreferUtil.getInstance().widthValue.toString()
        tvHightValue.text = PreferUtil.getInstance().hightValue.toString()
        tvItemSpacingValue.text = PreferUtil.getInstance().itemSpacingValue.toString()

        rlAll.setOnClickListener(this)
        rlDanger.setOnClickListener(this)
        rlPeril.setOnClickListener(this)
        rlSuper.setOnClickListener(this)
        rlOne.setOnClickListener(this)
        rlTwo.setOnClickListener(this)
        rlThree.setOnClickListener(this)
        rlEmpty.setOnClickListener(this)
        rlPresent.setOnClickListener(this)
        rlHospitalized.setOnClickListener(this)
        rlOperation.setOnClickListener(this)
        rlAdjust.setOnClickListener(this)
        ivItemAdd.setOnClickListener(this)
        ivItemCut.setOnClickListener(this)
        ivTypefaceAdd.setOnClickListener(this)
        ivTypefaceCut.setOnClickListener(this)
        ivWidthAdd.setOnClickListener(this)
        ivWidthCut.setOnClickListener(this)
        ivHightAdd.setOnClickListener(this)
        ivHightCut.setOnClickListener(this)
        rlAutoScroll.setOnClickListener(this)
        ivItemSpacingCut.setOnClickListener(this)
        ivItemSpacingAdd.setOnClickListener(this)
        rlRes.setOnClickListener(this)

    }

    override fun onResume() {
        super.onResume()
        getPatientList()
    }

    private fun getPatientList() {
        mPresenter.getPatientList(
            activity,
            "deptCode",
            PreferUtil.getInstance().deptCode,
            "bedPrefix",
            PreferUtil.getInstance().bedPrefix,
            "inFlag",
            PreferUtil.getInstance().inFlag
        )
    }

    private var scrollListener = object : RecyclerView.OnScrollListener() {
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            super.onScrolled(recyclerView, dx, dy)
            if (isAuto && isSlideToBottom(recyclerView)) {
                moveToPosition(manager!!, rvTitle, 1)
            }
        }
    }

    fun isSlideToBottom(recyclerView: RecyclerView?): Boolean {
        if (recyclerView == null) return false
        return recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange()
    }

    open fun moveToPosition(
        manager: LinearLayoutManager,
        mRecyclerView: RecyclerView,
        n: Int
    ) {
        val firstItem = manager.findFirstVisibleItemPosition()
        val lastItem = manager.findLastVisibleItemPosition()
        when {
            n <= firstItem -> {
                mRecyclerView.scrollToPosition(n)
            }
            n <= lastItem -> {
                val top = mRecyclerView.getChildAt(n - firstItem).top
                mRecyclerView.scrollBy(0, top)
            }
            else -> {
                mRecyclerView.scrollToPosition(n)
            }
        }
    }

    /**
    获取病人列表
     */
    override fun getPatientListSuccess(data: PatientListBean?) {
        initData(data!!)
    }

    /**
    获取护士列表
     */
    override fun getNurseListBeanSuccess(data: NurseListBean) {
        showCheckDialog(data)
    }

    /**
    获取标签分类
     */
    override fun getCategoryListBeanSuccess(data: CategoryListBean) {
        showCategoryDialog(data)
    }

    /**
     * 根据标签分类获取词典列表
     */
    override fun getCareLabelListSuccess(data: CareLabelListBean) {
        showCareLabelList(data)
    }

    /**
    更新护理标签
     */
    override fun getUpdateCareLabelSuccess(data: BaseBean) {
        ToastUtils.showLongToast(data.message)
        mPresenter.getPatientCareLabelList(activity, "patientId", patientItem?.patientId.toString())
        EventBus.getDefault().post(BaseEvenBus(BaseEvenBus.GETBOARDGET))
    }

    /**
     * 更新护理信息
     */
    override fun getUpdateNursingSuccess(data: BaseBean) {
        ToastUtils.showLongToast(data.message)
        getPatientList()
    }

    /**
    获取费用明细
     */
    override fun getFeeRecordListSuccess(data: FeeRecordListBean) {
        showFeeDialog(data)
    }

    /**
    获取检查报告列表
     */
    override fun getTestReportListSuccess(data: TestReportListBean) {
        showTestDialog(data)
    }

    /**
    获取检验报告列表
     */
    override fun getInspectReportListSuccess(data: InspectReportListBean) {
        showInspectDialog(data)
    }

    /**
    获取医嘱列表
     */
    override fun getOrderListSuccess(data: OrderListBean) {
        showDrugDialog(data)
    }

    /**
    获取体温列表
     */
    override fun getTemperatureListSuccess(data: TemBean) {
        showTemperatureListDialog(data)
    }
    /**
    获取血压列表
     */
    override fun getBloodPressListSuccess(data: BloodBean) {
        showBloodPressListDialog(data)
    }

    /**
    获取护理标签列表
     */
    override fun getPatientCareLabelListSuccess(data: PatientCareLabelListBean) {
        patientCareLabelAdapter?.setNewData(data.data)
        patientCareLabelAdapter?.notifyDataSetChanged()
        addCareLabelAdapter?.setNewData(data.data)
        addCareLabelAdapter?.notifyDataSetChanged()
        labelIds.clear()
        for (item in data.data) {
            labelIds.add(item.id)
        }
    }

    override fun showError(message: String?) {
//        ToastUtils.showShortToast(message)
    }

    override fun onListItemClick(item: PatientListBean.DataBean?) {
        patientItem = item
        showPatientDialog()
    }

    /**
    病人信息dialog
     */
    private fun showPatientDialog() {
        hidePatientDialog()
        val view =
            View.inflate(BaseApplication.getContext(), R.layout.dialog_patient, null)
        val tvName = view.findViewById<TextView>(R.id.tvName)
        val tvCode = view.findViewById<TextView>(R.id.tvCode)
        val tvBedCode = view.findViewById<TextView>(R.id.tvBedCode)
        val tvDiagnose = view.findViewById<TextView>(R.id.tvDiagnose)
        val tvDoctorName = view.findViewById<TextView>(R.id.tvDoctorName)
        val tvNurseLevel = view.findViewById<TextView>(R.id.tvNurseLevel)
        val btnCarelabel = view.findViewById<TextView>(R.id.btnCarelabel)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val btnSavePatient = view.findViewById<TextView>(R.id.btnSavePatient)
        val btnTest = view.findViewById<TextView>(R.id.btnTest)
        val btnInspect = view.findViewById<TextView>(R.id.btnInspect)
        val btnFee = view.findViewById<Button>(R.id.btnFee)
        val btnDrug = view.findViewById<Button>(R.id.btnDrug)
        val btnTem = view.findViewById<Button>(R.id.btnTem)
        val btnPre = view.findViewById<Button>(R.id.btnPre)
        val tvTimer = view.findViewById<TextView>(R.id.tvTimer)
        val tvChargeTypeName = view.findViewById<TextView>(R.id.tvChargeTypeName)
        rvPatientCareLabel = view.findViewById<RecyclerView>(R.id.rvPatientCareLabel)

        patientCareLabelAdapter = PatientCareLabelAdapter(null)
        rvPatientCareLabel?.adapter = patientCareLabelAdapter
        val manager = LinearLayoutManager(activity)
        manager.orientation = LinearLayoutManager.VERTICAL
        rvPatientCareLabel?.layoutManager = manager

        tvNName = view.findViewById<TextView>(R.id.tvNName)
        tvPName = view.findViewById<TextView>(R.id.tvPName)
        val rlNN = view.findViewById<RelativeLayout>(R.id.rlNN)
        val rlNP = view.findViewById<RelativeLayout>(R.id.rlNP)

        tvName.text = patientItem?.name
        tvCode.text = patientItem?.bedName
        tvBedCode.text = patientItem?.cureNo
        tvDiagnose.text = patientItem?.diagnose
        tvDoctorName.text = patientItem?.doctorName
        tvNurseLevel.text = patientItem?.nurseLevelName
        tvNName?.text = patientItem?.nurseName
        tvPName?.text = patientItem?.nurseName2
        tvTimer?.text = patientItem?.inTime
        tvChargeTypeName?.text = patientItem?.chargeTypeName

        nurseCode = patientItem?.nurseCode
        nurseCode2 = patientItem?.nurseCode2

        rlNN.setOnClickListener(this)
        rlNP.setOnClickListener(this)
        btnCarelabel.setOnClickListener(this)
        btnSavePatient.setOnClickListener(this)
        ivDelete.setOnClickListener {
            hidePatientDialog()
        }
        btnTest.setOnClickListener {
            patientItem?.cureNo?.let { it1 ->
                mPresenter.getTestReportList(
                    activity, "admissionId",
                    it1
                )
            }
        }
        btnInspect.setOnClickListener {
            patientItem?.cureNo?.let { it1 ->
                mPresenter.getInspectReportList(
                    activity, "admissionId",
                    it1
                )
            }
        }

        btnFee.setOnClickListener {
            patientItem?.cureNo?.let { it1 ->
                mPresenter.getFeeRecordList(
                    activity, "admissionId",
                    it1
                )
            }
        }

        btnDrug.setOnClickListener {
            patientItem?.cureNo?.let { it1 ->
                mPresenter.getOrderList(
                    activity, "admissionId",
                    it1
                )
            }
        }

        btnTem.setOnClickListener {
            patientItem?.patientId?.let { it1 ->
                mPresenter.getTemperatureList(
                    activity, "patientId",
                    it1.toString()
                )
            }
        }

        btnPre.setOnClickListener {
            patientItem?.patientId?.let { it1 ->
                mPresenter.getBloodPressList(
                    activity, "patientId",
                    it1.toString()
                )
            }
        }

        patientDialog = CustomDialog(activity, 500, 500, view, R.style.MyDialog)
        patientDialog?.setCancelable(true)
        patientDialog?.show()
        mPresenter.getPatientCareLabelList(activity, "patientId", patientItem?.patientId.toString())

    }

    /**
    选择护士dialog
     */
    private fun showCheckDialog(data: NurseListBean) {
        hideCheckDialog()
        val view =
            View.inflate(BaseApplication.getContext(), R.layout.dialog_check, null)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val rvCheck = view.findViewById<RecyclerView>(R.id.rvCheck)

        val adapterCheck = CheckAdapter(data.data)
        rvCheck.adapter = adapterCheck
        val manage = LinearLayoutManager(activity)
        manage.orientation = LinearLayoutManager.VERTICAL
        rvCheck.layoutManager = manage
        adapterCheck.onListItemClick(this)

        ivDelete.setOnClickListener {
            hideCheckDialog()
        }

        checkDialog = CustomDialog(activity, 300, 300, view, R.style.MyDialog)
        checkDialog?.setCancelable(true)
        checkDialog?.show()

    }

    /**
    添加警示标签
     */
    @SuppressLint("SetTextI18n")
    private fun showEditCareLabelDialog() {
        hideCareLabelDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_carelabel, null)

        val rlCarelabel = view.findViewById<RelativeLayout>(R.id.rlCarelabel)
        val rlCheckColor = view.findViewById<RelativeLayout>(R.id.rlCheckColor)
        val rlFontColor = view.findViewById<RelativeLayout>(R.id.rlFontColor)
        val tvCode = view.findViewById<TextView>(R.id.tvCode)
        val btnColorPost = view.findViewById<Button>(R.id.btnColorPost)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        tvColor = view.findViewById<TextView>(R.id.tvColor)
        tvFontColor = view.findViewById<TextView>(R.id.tvFontColor)
        tvEditCarelabel = view.findViewById<TextView>(R.id.tvEditCarelabel)
        rvAddCarelabel = view.findViewById<RecyclerView>(R.id.rvAddCarelabel)
        addCareLabelAdapter = PatientCareLabelAdapter(null)
        rvAddCarelabel?.adapter = addCareLabelAdapter
        val manager = LinearLayoutManager(activity)
        rvAddCarelabel?.layoutManager = manager

        tvCode.text = patientItem?.bedName + " - " + patientItem?.name

        rlCarelabel.setOnClickListener(this)
        rlCheckColor.setOnClickListener(this)
        rlFontColor.setOnClickListener(this)
        btnColorPost.setOnClickListener(this)
        ivDelete.setOnClickListener {
            hideCareLabelDialog()
        }

        val itemDragAndSwipeCallback = ItemDragAndSwipeCallback(addCareLabelAdapter)
        val itemTouchHelper = ItemTouchHelper(itemDragAndSwipeCallback)
        itemTouchHelper.attachToRecyclerView(rvAddCarelabel)
        itemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START or ItemTouchHelper.END)

        addCareLabelAdapter?.enableSwipeItem()
        addCareLabelAdapter?.setOnItemSwipeListener(onItemSwipeListener)

        careLabelDialog = CustomDialog(activity, 500, 500, view, R.style.MyDialog)
        careLabelDialog?.setCancelable(true)
        careLabelDialog?.show()

    }

    private var onItemSwipeListener: OnItemSwipeListener = object : OnItemSwipeListener {
        override fun clearView(p0: RecyclerView.ViewHolder?, p1: Int) {
        }

        override fun onItemSwiped(p0: RecyclerView.ViewHolder?, p1: Int) {
            val body = UpdateCareLabelBody()
            if (patientItem != null) {
                body.patientId = patientItem?.patientId!!
                labelIds.removeAt(p1)
                body.labelIds = labelIds
                mPresenter.getUpdateCareLabel(activity, body)
            }
        }

        override fun onItemSwipeStart(p0: RecyclerView.ViewHolder?, p1: Int) {

        }

        override fun onItemSwipeMoving(
            p0: Canvas?,
            p1: RecyclerView.ViewHolder?,
            p2: Float,
            p3: Float,
            p4: Boolean
        ) {
        }
    }

    /**
    护理标签列表dialog
     */
    private fun showCategoryDialog(data: CategoryListBean) {
        hideCategoryDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_category, null)
        val rvCategory = view.findViewById<RecyclerView>(R.id.rvCategory)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val adapter = CategoryAdapter(data.data?.toMutableList())
        rvCategory.adapter = adapter
        val manager = LinearLayoutManager(activity)
        manager.orientation = LinearLayoutManager.VERTICAL
        rvCategory.layoutManager = manager
        adapter.onListItemClick(object : CategoryAdapter.onListItemClick {
            override fun onListItemClick(item: String?) {
                hideCategoryDialog()
                if (item != null) {
                    mPresenter.getCareLabelList(activity, "labelCat", item)
                }
            }
        })

        ivDelete.setOnClickListener {
            hideCategoryDialog()
        }

        categoryListDialog = CustomDialog(activity, 500, 500, view, R.style.MyDialog)
        categoryListDialog?.setCancelable(true)
        categoryListDialog?.show()

    }

    /**
    护理标签列表dialog
     */
    private fun showCareLabelList(data: CareLabelListBean) {
        hideCareLabelListDialog()

        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_category, null)
        val rvCategory = view.findViewById<RecyclerView>(R.id.rvCategory)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val adapter = CareLabelAdapter(data.data)
        rvCategory.adapter = adapter
        val manager = LinearLayoutManager(activity)
        manager.orientation = LinearLayoutManager.VERTICAL
        rvCategory.layoutManager = manager
        adapter.onListItemClick(object : CareLabelAdapter.onListItemClick {
            override fun onListItemClick(item: CareLabelListBean.DataBean?) {
                hideCareLabelListDialog()
                tvEditCarelabel?.text = item?.labelName
                labelName = item?.labelName
                labelId = item?.id
                labelIds.add(item?.id!!)
            }
        })

        ivDelete.setOnClickListener {
            hideCareLabelListDialog()
        }

        careLabelListDialog = CustomDialog(activity, 500, 500, view, R.style.MyDialog)
        careLabelListDialog?.setCancelable(true)
        careLabelListDialog?.show()

    }

    /**
    颜色选择dialog
     */
    private fun showCheckColor() {
        hideCheckColorDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_checkdialog, null)
        val colorPicker = view.findViewById<ColorPickerView>(R.id.colorPicker)
        val btnCancel = view.findViewById<Button>(R.id.btnCancel)
        val btnSave = view.findViewById<Button>(R.id.btnSave)

        colorPicker?.setCornorCircleType(1)
        colorPicker?.isDrawMagnifyBounds = false
        colorPicker?.isDrawMagnifyCircle = false

        btnCancel.setOnClickListener {
            hideCheckColorDialog()
        }

        btnSave.setOnClickListener {
            hideCheckColorDialog()
            val hexColor = "#" + Integer.toHexString(colorPicker?.curRGBColor!!).substring(2)
            when (typeCheckColor) {
                0 -> {
                    tvColor?.setBackgroundColor(Color.parseColor(hexColor))
                    bgColor = hexColor
                }
                1 -> {
                    tvFontColor?.setBackgroundColor(Color.parseColor(hexColor))
                    fontColor = hexColor
                }
            }
        }

        checkColorDiaolog = CustomDialog(activity, view, R.style.MyDialog)
        checkColorDiaolog?.setCancelable(true)
        checkColorDiaolog?.show()

    }

    /**
    检查报告dialog
     */
    @SuppressLint("SetTextI18n")
    private fun showTestDialog(data: TestReportListBean) {
        hideTestDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_test, null)

        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val rvTest = view.findViewById<RecyclerView>(R.id.rvTest)
        val tvNo = view.findViewById<TextView>(R.id.tvNo)
        if (data.data.isEmpty() || data.data.size <= 0) {
            tvNo.visibility = View.VISIBLE
            rvTest.visibility = View.GONE
        } else {
            tvNo.visibility = View.GONE
            rvTest.visibility = View.VISIBLE
            val adapter = TestAdapter(data.data)
            rvTest.adapter = adapter
            val manager = LinearLayoutManager(activity)
            rvTest.layoutManager = manager
        }

        ivDelete.setOnClickListener {
            hideTestDialog()
        }

        testDiaolog = CustomDialog(activity, 800, 500, view, R.style.MyDialog)
        testDiaolog?.setCancelable(true)
        testDiaolog?.show()

    }

    /**
    检验报告dialog
     */
    private fun showInspectDialog(data: InspectReportListBean) {
        hideInspectDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_inspect, null)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val rvInspect = view.findViewById<RecyclerView>(R.id.rvInspect)
        val tvName = view.findViewById<TextView>(R.id.tvName)
        val tvSex = view.findViewById<TextView>(R.id.tvSex)
        val tvAge = view.findViewById<TextView>(R.id.tvAge)
        val tvCureNo = view.findViewById<TextView>(R.id.tvCureNo)
        val tvBedCode = view.findViewById<TextView>(R.id.tvBedCode)

        tvName.text = patientItem?.name
        tvSex.text = patientItem?.sexText
        tvAge.text = patientItem?.age
        tvCureNo.text = patientItem?.cureNo
        tvBedCode.text = patientItem?.bedName

        val adapter = InspectAdapter(data.data)
        rvInspect.adapter = adapter
        val manager = LinearLayoutManager(activity)
        rvInspect.layoutManager = manager

        ivDelete.setOnClickListener {
            hideInspectDialog()
        }

        inspectDiaolog = CustomDialog(activity, 600, 500, view, R.style.MyDialog)
        inspectDiaolog?.setCancelable(true)
        inspectDiaolog?.show()

    }

    /**
    费用报告dialog
     */
    private fun showFeeDialog(data: FeeRecordListBean?) {

        val resultMap: MutableMap<String, MutableList<FeeRecordListBean.DataBean>> =
            HashMap()

        for ((index, item) in data?.data?.withIndex()!!) {
            //该日期已存在，则放入该集合
            val time = TimeUtils.string2Millis(item.feeDate, "yyyy-MM-dd")
            if (resultMap.containsKey(time.toString())) {
                resultMap[time.toString()]?.add(item)
            } else {
                val itemList: MutableList<FeeRecordListBean.DataBean> = ArrayList()
                itemList.add(item)
                resultMap[time.toString()] = itemList
            }
        }

        val feeDataBeanList = mutableListOf<FeeDataBean>()
        for ((key, value) in resultMap) {
            val feeDataBean = FeeDataBean()
            feeDataBean.time = key
            feeDataBean.dataBeanList = value
            var b = 0.0
            for (num in feeDataBean.dataBeanList) {
                b += num.totalAmount
            }
            feeDataBean.totalMoney = CommonUtil.getNoMoreThanTwoDigits(b)
            feeDataBeanList.add(feeDataBean)
        }

        Collections.sort(feeDataBeanList, Comparator<FeeDataBean?> { o1, o2 ->
            if (o1?.time?.toLong()!! < o2?.time?.toLong()!!) {
                return@Comparator 1
            }
            if (o1.time?.toLong()!! == o2.time?.toLong()!!) {
                0
            } else -1
        })

        hideFeeDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_fee, null)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val rvFee = view.findViewById<RecyclerView>(R.id.rvFee)
        val adapterFee = FeeAdapter(feeDataBeanList)
        rvFee.adapter = adapterFee
        val manager = LinearLayoutManager(activity)
        rvFee.layoutManager = manager

        ivDelete.setOnClickListener {
            hideFeeDialog()
        }

        feeDiaolog = CustomDialog(activity, 800, 500, view, R.style.MyDialog)
        feeDiaolog?.setCancelable(true)
        feeDiaolog?.show()

    }

    /**
    药物报告dialog
     */
    private fun showDrugDialog(data: OrderListBean) {

        val resultMap: MutableMap<String, MutableList<OrderListBean.DataBean>> =
            HashMap()

        for ((index, item) in data.data?.withIndex()!!) {
            //该日期已存在，则放入该集合
            val time = TimeUtils.string2Millis(item.startTime, "yyyy-MM-dd")
            if (resultMap.containsKey(time.toString())) {
                resultMap[time.toString()]?.add(item)
            } else {
                val itemList: MutableList<OrderListBean.DataBean> = ArrayList()
                itemList.add(item)
                resultMap[time.toString()] = itemList
            }
        }

        val drugDataBeanList = mutableListOf<DrugDataBean>()
        for ((key, value) in resultMap) {
            val drugDataBean = DrugDataBean()
            drugDataBean.time = key
            drugDataBean.dataBeanList = value
            drugDataBeanList.add(drugDataBean)
        }

        Collections.sort(drugDataBeanList, Comparator<DrugDataBean?> { o1, o2 ->
            if (o1?.time?.toLong()!! < o2?.time?.toLong()!!) {
                return@Comparator 1
            }
            if (o1.time?.toLong()!! == o2.time?.toLong()!!) {
                0
            } else -1
        })


        hideDrugDialog()
        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_drug, null)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)
        val rvDrug = view.findViewById<RecyclerView>(R.id.rvDrug)

        val adapter = DrugAdapter(drugDataBeanList)
        rvDrug.adapter = adapter
        val manager = LinearLayoutManager(activity)
        rvDrug.layoutManager = manager

        ivDelete.setOnClickListener {
            hideDrugDialog()
        }

        drugDiaolog = CustomDialog(activity, 800, 500, view, R.style.MyDialog)
        drugDiaolog?.setCancelable(true)
        drugDiaolog?.show()

    }

    /**
     *温度记录 dialog
     */
    private fun showTemperatureListDialog(data: TemBean) {
        hideTemperatureListDialog()

        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_tem_list, null)
        val rvTem = view.findViewById<RecyclerView>(R.id.rvTem)
        val tvNo = view.findViewById<TextView>(R.id.tvNo)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)

        if (data.data == null || data.data?.size!! <= 0) {
            tvNo.visibility = View.VISIBLE
            rvTem.visibility = View.GONE
        } else {
            tvNo.visibility = View.GONE
            rvTem.visibility = View.VISIBLE

//            Collections.sort(data.data, Comparator<TemBean.DataBean?> { o1, o2 ->
//                if (o1?.createTime?.toLong()!! < o2?.createTime?.toLong()!!) {
//                    return@Comparator 1
//                }
//                if (o1.createTime?.toLong()!! == o2.createTime?.toLong()!!) {
//                    0
//                } else -1
//            })

            val temAdapter = TemAdapter(data.data)
            rvTem.adapter = temAdapter
            val manager = LinearLayoutManager(activity)
            rvTem.layoutManager = manager

        }

        ivDelete.setOnClickListener {
            hideTemperatureListDialog()
        }

        temDiaolog = CustomDialog(activity, 800, 500, view, R.style.MyDialog)
        temDiaolog?.setCancelable(true)
        temDiaolog?.show()

    }

    private  fun showBloodPressListDialog(data:BloodBean){

        hideBloodPressListDialog()

        val view = View.inflate(BaseApplication.getContext(), R.layout.dialog_blood_list, null)
        val rvTem = view.findViewById<RecyclerView>(R.id.rvBlood)
        val tvNo = view.findViewById<TextView>(R.id.tvNo)
        val ivDelete = view.findViewById<ImageView>(R.id.ivDelete)

        if (data.data == null || data.data?.size!! <= 0) {
            tvNo.visibility = View.VISIBLE
            rvTem.visibility = View.GONE
        } else {
            tvNo.visibility = View.GONE
            rvTem.visibility = View.VISIBLE

            val temAdapter = BloodAdapter(data.data)
            rvTem.adapter = temAdapter
            val manager = LinearLayoutManager(activity)
            rvTem.layoutManager = manager

        }

        ivDelete.setOnClickListener {
            hideBloodPressListDialog()
        }

        bloodDiaolog = CustomDialog(activity, 800, 500, view, R.style.MyDialog)
        bloodDiaolog?.setCancelable(true)
        bloodDiaolog?.show()

    }


    override fun onListItemClick(item: NurseListBean.DataBean?) {
        hideCheckDialog()
        when (typeCheck) {
            0 -> {
                tvNName?.text = item?.name
                nurseCode = item?.code
            }
            1 -> {
                tvPName?.text = item?.name
                nurseCode2 = item?.code
            }
        }
    }

    private fun hideCareLabelDialog() {
        if (careLabelDialog != null && careLabelDialog?.isShowing!!) {
            careLabelDialog?.dismiss()
            careLabelDialog = null
        }
        bgColor = null
        fontColor = null
        labelName = null
    }

    private fun hideCheckDialog() {
        if (checkDialog != null && checkDialog?.isShowing!!) {
            checkDialog?.dismiss()
            checkDialog = null
        }
    }

    private fun hidePatientDialog() {
        if (patientDialog != null && patientDialog?.isShowing!!) {
            patientDialog?.dismiss()
            patientDialog = null
        }
        nurseCode2 = null
        nurseCode = null
    }

    private fun hideCategoryDialog() {
        if (categoryListDialog != null && categoryListDialog?.isShowing!!) {
            categoryListDialog?.dismiss()
            categoryListDialog = null
        }
    }

    private fun hideCareLabelListDialog() {
        if (careLabelListDialog != null && careLabelListDialog?.isShowing!!) {
            careLabelListDialog?.dismiss()
            careLabelListDialog = null
        }
    }

    private fun hideCheckColorDialog() {
        if (checkColorDiaolog != null && checkColorDiaolog?.isShowing!!) {
            checkColorDiaolog?.dismiss()
            checkColorDiaolog = null
        }
    }

    private fun hideTestDialog() {
        if (testDiaolog != null && testDiaolog?.isShowing!!) {
            testDiaolog?.dismiss()
            testDiaolog = null
        }
    }

    private fun hideInspectDialog() {
        if (inspectDiaolog != null && inspectDiaolog?.isShowing!!) {
            inspectDiaolog?.dismiss()
            inspectDiaolog = null
        }
    }

    private fun hideFeeDialog() {
        if (feeDiaolog != null && feeDiaolog?.isShowing!!) {
            feeDiaolog?.dismiss()
            feeDiaolog = null
        }
    }

    private fun hideDrugDialog() {
        if (drugDiaolog != null && drugDiaolog?.isShowing!!) {
            drugDiaolog?.dismiss()
            drugDiaolog = null
        }
    }

    private fun hideTemperatureListDialog() {
        if (temDiaolog != null && temDiaolog?.isShowing!!) {
            temDiaolog?.dismiss()
            temDiaolog = null
        }
    }

    private fun hideBloodPressListDialog(){
        if (bloodDiaolog != null && bloodDiaolog?.isShowing!!) {
            bloodDiaolog?.dismiss()
            bloodDiaolog = null
        }
    }

    private fun initData(patientListBean: PatientListBean) {
        patientListAll.clear()
        patientListAll = patientListBean.data
        adapter?.setNewData(patientListAll)
        adapter?.notifyDataSetChanged()
        checkView(R.id.rlAll)

        patientListOne.clear()
        patientListTwo.clear()
        patientListThree.clear()
        patientListDanger.clear()
        patientListPeril.clear()
        patientListSuper.clear()
        patientListHospitalized.clear()
        patientListOperation.clear()

        for ((i, item) in patientListBean.data.withIndex()) {
            if (item.bedStatus == 1 && !item.isTodayOut) {
                patientListDanger.add(item)
            }

            when (patientListBean.data[i].nurseLevelType) {
                1 -> { //Ⅰ级护理
                    patientListOne.add(patientListBean.data[i])
                }

                2 -> {// Ⅱ级护理
                    patientListTwo.add(patientListBean.data[i])
                }

                3 -> {// Ⅲ级护理
                    patientListThree.add(patientListBean.data[i])
                }

//                4 ->                     // 重级护理
//                    patientListDanger.add(patientListBean.data[i])

                5 -> {  //危级护理
                    patientListPeril.add(patientListBean.data[i])
                }

                6 -> {  //特级护理
                    patientListSuper.add(patientListBean.data[i])
                }

//                7 -> {   //出院病人
//                    patientListOperation.add(patientListBean.data[i])
//                    patientListDanger.add(patientListBean.data[i])
//                }

            }
            if (patientListBean.data[i].isToday) {
                patientListHospitalized.add(patientListBean.data[i])
            }

            if (patientListBean.data[i].isTodayOut) {
                patientListOperation.add(patientListBean.data[i])
            }
        }

        tvMessageAll.text = patientListAll.size.toString()
        tvMessageDanger.text = patientListDanger.size.toString()
        tvMessagePerill.text = patientListPeril.size.toString()
        tvMessageSuper.text = patientListSuper.size.toString()
        tvMessageOne.text = patientListOne.size.toString()
        tvMessageTwo.text = patientListTwo.size.toString()
        tvMessageThree.text = patientListThree.size.toString()
        tvMessageEmpty.text = patientListEmpty.size.toString()
        tvMessagePresent.text = patientListPresent.size.toString()
        tvMessageOperation.text = patientListOperation.size.toString()
        tvMessageHospitalized.text = patientListHospitalized.size.toString()

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlNN -> {
                mPresenter.getNurseListBean(activity, "deptNo", PreferUtil.getInstance().deptCode)
                typeCheck = 0
            }
            R.id.rlNP -> {
                mPresenter.getNurseListBean(activity, "deptNo", PreferUtil.getInstance().deptCode)
                typeCheck = 1
            }

            R.id.btnCarelabel -> {
                showEditCareLabelDialog()
                mPresenter.getPatientCareLabelList(
                    activity,
                    "patientId",
                    patientItem?.patientId.toString()
                )
            }

            R.id.rlCarelabel -> {
                mPresenter.getCategoryListBean(activity)
            }

            R.id.rlCheckColor -> {
                typeCheckColor = 0
                showCheckColor()
            }

            R.id.rlFontColor -> {
                typeCheckColor = 1
                showCheckColor()
            }

            R.id.btnColorPost -> {
                if (labelName == null || labelName == "") {
                    ToastUtils.showShortToast("请选择标签")
                    return
                }
                val body = UpdateCareLabelBody()
                if (patientItem != null) {
                    body.patientId = patientItem?.patientId!!
                    labelIds.add(labelId!!)
                    body.labelIds = labelIds
                    mPresenter.getUpdateCareLabel(activity, body)
                }

            }

            R.id.btnSavePatient -> {
                val body = UpdateNursingBody()
                body.updateTime = TimeUtils.getNowTimeString()
                body.patientId = patientItem?.patientId!!
                body.nurseCode = nurseCode
                body.nurseCode2 = nurseCode2
                body.doctorCode = patientItem?.doctorCode
                body.diagnose = patientItem?.diagnose
                mPresenter.getUpdateNursing(activity, body)

            }

            R.id.rlAll -> {
                adapter?.setNewData(patientListAll)
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlAll)
//                scheduledFuture = BaseApplication.MAIN_EXECUTOR.scheduleWithFixedDelay({
//                    isAuto = true
//                    rvTitle.smoothScrollBy(0, 10)
//                }, 1000, 1000, TimeUnit.MILLISECONDS)
//                tvAutoScroll.setText(R.string.stop_rolling)
            }
            R.id.rlDanger -> {
                scheduledFuture?.cancel(false)
                isAuto = false
                adapter?.setNewData(patientListDanger)
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlDanger)
            }
            R.id.rlPeril -> {
                adapter?.setNewData(patientListPeril)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
            }
            R.id.rlSuper -> {
                adapter?.setNewData(patientListSuper)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
            }
            R.id.rlOne -> {
                adapter?.setNewData(patientListOne)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlOne)
            }

            R.id.rlTwo -> {
                adapter?.setNewData(patientListTwo)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlTwo)
            }

            R.id.rlThree -> {
                adapter?.setNewData(patientListThree)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlThree)
            }

            R.id.rlEmpty -> {
                adapter?.setNewData(patientListEmpty)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
            }

            R.id.rlPresent -> {
                adapter?.setNewData(patientListPresent)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()

            }

            R.id.rlHospitalized -> {
                adapter?.setNewData(patientListHospitalized)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlHospitalized)
            }

            R.id.rlOperation -> {

                adapter?.setNewData(patientListOperation)
                scheduledFuture?.cancel(false)
                scheduledFuture = null
                isAuto = false
                adapter?.notifyDataSetChanged()
                checkView(R.id.rlOperation)
            }

            R.id.rlAdjust -> {
                if (llSb.visibility == View.VISIBLE) {
                    llSb.visibility = View.GONE
                } else {
                    llSb.visibility = View.VISIBLE
                }
            }
            R.id.ivItemAdd -> {
                var itemValue = PreferUtil.getInstance().itemValue
                val addV = ++itemValue
                rvTitle.layoutManager = GridLayoutManager(getSupportActivity(), addV)
                adapter?.notifyDataSetChanged()
                tvItemValue.text = addV.toString()
                PreferUtil.getInstance().itemValue = addV
            }
            R.id.ivItemCut -> {
                var cutItemValue = PreferUtil.getInstance().itemValue
                val cutV = --cutItemValue
                rvTitle.layoutManager = GridLayoutManager(getSupportActivity(), cutV)
                adapter?.notifyDataSetChanged()
                tvItemValue.text = cutV.toString()
                PreferUtil.getInstance().itemValue = cutV
            }

//            R.id.ivItemSpacingAdd->{
//                var itemSpacingAddValue = PreferUtil.getInstance().itemSpacingValue
//                val addS = ++itemSpacingAddValue
//                rvTitle.addItemDecoration(SpacesItemDecoration(addS))
//                adapter?.notifyDataSetChanged()
//                tvItemSpacingValue.text = addS.toString()
//                PreferUtil.getInstance().itemSpacingValue = addS
//            }
//
//            R.id.ivItemSpacingCut->{
//                var itemSpacingCutValue = PreferUtil.getInstance().itemSpacingValue
//                val cutS = --itemSpacingCutValue
//                rvTitle.addItemDecoration(SpacesItemDecoration(cutS))
//                adapter?.notifyDataSetChanged()
//                tvItemSpacingValue.text = cutS.toString()
//                PreferUtil.getInstance().itemSpacingValue = cutS
//            }

            R.id.ivTypefaceAdd -> {
                var addTypecfaceValue = PreferUtil.getInstance().typefaceValue
                var addNameTypefaceValuie = PreferUtil.getInstance().typefaceNameValue
                var addInfusionTypefaceValue =
                    PreferUtil.getInstance().infusionTypefaceValue
                val addN = ++addNameTypefaceValuie
                val addT = ++addTypecfaceValue
                val addI = ++addInfusionTypefaceValue
                adapter?.setTextSize(addN, addT, addI)
                adapter?.notifyDataSetChanged()
                tvTypefaceValue.text = addT.toString()
                PreferUtil.getInstance().typefaceValue = addT
                PreferUtil.getInstance().setTypefaceNmeValue(addN)
                PreferUtil.getInstance().infusionTypefaceValue = addI
            }
            R.id.ivTypefaceCut -> {
                var cutTypecfaceValue = PreferUtil.getInstance().typefaceValue
                var cutNameTypefaceValue = PreferUtil.getInstance().typefaceNameValue
                var cutInfusionTypefaceValue =
                    PreferUtil.getInstance().infusionTypefaceValue
                val cutN = --cutNameTypefaceValue
                val cutT = --cutTypecfaceValue
                val cutI = --cutInfusionTypefaceValue
                adapter?.setTextSize(cutN, cutT, cutI)
                adapter?.notifyDataSetChanged()
                tvTypefaceValue.text = cutT.toString()
                PreferUtil.getInstance().typefaceValue = cutT
                PreferUtil.getInstance().setTypefaceNmeValue(cutN)
                PreferUtil.getInstance().infusionTypefaceValue = cutI
            }
            R.id.ivWidthAdd -> {
                var addWidthValue = PreferUtil.getInstance().widthValue
                val addW = ++addWidthValue
                val addWParams =
                    ViewGroup.LayoutParams(addW, PreferUtil.getInstance().hightValue)
                adapter?.setLayoutParams(addWParams)
                adapter?.notifyDataSetChanged()
                PreferUtil.getInstance().widthValue = addW
                tvWidthValue.text = addW.toString()
            }
            R.id.ivWidthCut -> {
                var cutWidthValue = PreferUtil.getInstance().widthValue
                val cutW = --cutWidthValue
                val cutWParams =
                    ViewGroup.LayoutParams(cutW, PreferUtil.getInstance().hightValue)
                adapter?.setLayoutParams(cutWParams)
                adapter?.notifyDataSetChanged()
                PreferUtil.getInstance().widthValue = cutW
                tvWidthValue.text = cutW.toString()
            }
            R.id.ivHightAdd -> {
                var addHightValue = PreferUtil.getInstance().hightValue
                val addH = ++addHightValue
                val addHParams =
                    ViewGroup.LayoutParams(PreferUtil.getInstance().widthValue, addH)
                adapter?.setLayoutParams(addHParams)
                adapter?.notifyDataSetChanged()
                PreferUtil.getInstance().hightValue = addH
                tvHightValue.text = addH.toString()
            }
            R.id.ivHightCut -> {
                var cutHightValue = PreferUtil.getInstance().hightValue
                val cutH = --cutHightValue
                val cutHParams =
                    ViewGroup.LayoutParams(PreferUtil.getInstance().widthValue, cutH)
                adapter?.setLayoutParams(cutHParams)
                adapter?.notifyDataSetChanged()
                PreferUtil.getInstance().hightValue = cutH
                tvHightValue.text = cutH.toString()
            }
            R.id.rlAutoScroll -> {
                if (tvAutoScroll.text == this.resources.getString(R.string.stop_rolling)) {
                    scheduledFuture?.cancel(false)
                    scheduledFuture = null
                    isAuto = false
                    adapter?.notifyDataSetChanged()
                    tvAutoScroll.setText(R.string.start_rolling)
                } else {
                    adapter?.notifyDataSetChanged()
                    scheduledFuture = BaseApplication.MAIN_EXECUTOR.scheduleWithFixedDelay({
                        isAuto = true
                        rvTitle.smoothScrollBy(0, 10)
                    }, 1000, 1000, TimeUnit.MILLISECONDS)
                    tvAutoScroll.text = getString(R.string.stop_rolling)
                }
            }

            R.id.rlRes -> {
                getPatientList()
            }
        }
    }

    private fun checkView(id: Int?) {
        when (id) {
            R.id.rlAll -> {
                rlAll.setBackgroundResource(R.drawable.rl_p_bg)
                tv_all.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlDanger -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_p_bg)
                tv_danger.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlOne -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_p_bg)
                tvOne.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlTwo -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_p_bg)
                tvTwo.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlThree -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_p_bg)
                tvThree.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlHospitalized -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_p_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.color_68ADFF))

                rlOperation.setBackgroundResource(R.drawable.rl_bg)
                tvOperation.setTextColor(resources.getColor(R.color.white))

            }
            R.id.rlOperation -> {
                rlAll.setBackgroundResource(R.drawable.rl_bg)
                tv_all.setTextColor(resources.getColor(R.color.white))

                rlDanger.setBackgroundResource(R.drawable.rl_bg)
                tv_danger.setTextColor(resources.getColor(R.color.white))

                rlOne.setBackgroundResource(R.drawable.rl_bg)
                tvOne.setTextColor(resources.getColor(R.color.white))

                rlTwo.setBackgroundResource(R.drawable.rl_bg)
                tvTwo.setTextColor(resources.getColor(R.color.white))

                rlThree.setBackgroundResource(R.drawable.rl_bg)
                tvThree.setTextColor(resources.getColor(R.color.white))

                rlHospitalized.setBackgroundResource(R.drawable.rl_bg)
                tvHospitalized.setTextColor(resources.getColor(R.color.white))

                rlOperation.setBackgroundResource(R.drawable.rl_p_bg)
                tvOperation.setTextColor(resources.getColor(R.color.color_68ADFF))

            }
        }
    }


}